package javatest;

import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core;
import com.vpx.VpxDecoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

/**
 * @author sad
 */
public class Decoder {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        Utils.loadLibraries();

        InputStream stream = new FileInputStream(new File("d:/encoded.p"));
        byte[] bytes = new byte[(int) new File("d:/encoded.p").length()];
        stream.read(bytes);
        int offset = 12;
        byte[] nb = bytes = Arrays.copyOfRange(bytes, offset, bytes.length + offset);
        VpxDecoder decoder = new VpxDecoder(320, 240);
        opencv_core.IplImage decodedImage = opencv_core.cvCreateImage(opencv_core.cvSize(320, 240), 8, 3);
        decoder.decodeImage(decodedImage, nb);

        CanvasFrame frame = new CanvasFrame("");
        frame.setDefaultCloseOperation(CanvasFrame.EXIT_ON_CLOSE);
        frame.setSize(decodedImage.width(), decodedImage.height());
        frame.setVisible(true);
        frame.showImage(decodedImage, false);
    }
}
